package com.sgb.goods.entity;

import android.text.TextUtils;

import com.contrarywind.interfaces.IPickerViewData;
import com.google.gson.annotations.SerializedName;

import java.io.Serializable;
import java.util.List;

public class FilterEntity<T> implements Serializable , IPickerViewData {

    @SerializedName(value = "name", alternate = {"val","attributeName"})
    private String name;
    @SerializedName("no")
    private String no;
    @SerializedName(value = "unit", alternate = {"attributeValUnit"})
    private String unit;
    @SerializedName(value = "startVal", alternate = {"attributeVal"})
    private String startVal;
    @SerializedName(value = "endVal")
    private String endVal;
    @SerializedName(value = "attributeNo",alternate = {"attributeValNo"})
    private String attributeNo;
    @SerializedName(value = "type")
    private int type;
    @SerializedName(value = "children", alternate = {"valList", "vals","attributeValList"})
    T children;
    @SerializedName(value = "attrValList")
    List<AreaEntity> attrValList;
    @SerializedName(value = "attrKey")
    private int attrKey; //租赁属性:是否是必须属性 1表示必须

    public String getNo() {
        if (TextUtils.isEmpty(no)){
            return attributeNo;
        }
        return no;
    }

    public String getStartToEndVal() {
        return TextUtils.isEmpty(endVal) ? startVal : startVal + "-" + endVal;
    }

    @Override
    public String getPickerViewText() {
        return startVal;
    }

    @Override
    public String toString() {
        return "{name:" + name+",no:" + no +"}";
    }

    public boolean isInput(){
        if (children == null){
            return true;
        }
        if (children instanceof List){
            List valList = (List)children;
            return valList.isEmpty();
        }
        return true;
    }

    public static class AreaEntity implements IPickerViewData {

        @SerializedName(value = "simpleName", alternate = {"name"})
        public String simpleName;
        @SerializedName("no")
        public String no;

        @Override
        public String getPickerViewText() {
            return simpleName;
        }
    }
}
